
Alkaline.Processing.PropertyDescriptor = function(thisObj, propertyName, condition, startVal) {
	this.thisObj = thisObj;
	this.condition = condition;
	this.valueDistribution = this.startVal = startVal;
	this.docComment = null;
	this.name = propertyName;
	this.access = null;	// private, protected, public
	if (typeof this.name === "string")
		if (this.name.charAt(0) === '_')
			this.access = 'private';
		else
			this.access = 'public';
}
Alkaline.Processing.PropertyDescriptor.ACCESS_MODIFIERS = [
	// from least visible to most visible; in case of conflict, the most visible modifier is kept
	"private", "protected", "public"
];

Alkaline.Processing.PropertyDescriptor.init = function() {
	var mods = Alkaline.Processing.PropertyDescriptor.ACCESS_MODIFIERS;
	var rxs = mods.RegExps = [];
	for (var i = 0; i < mods.length; i++)
		rxs[i] = new RegExp('^@' + mods[i] + '\\s*$', 'im');
}

Alkaline.Processing.PropertyDescriptor.prototype.setValue = function(condition, newValue) {
	// check if writable
	// execute the setter
	this.valueDistribution.setValue(condition, newValue);
}

Alkaline.Processing.PropertyDescriptor.prototype.getValue = function(condition) {
	// execute the getter
	return this.valueDistribution.getValue(condition);
}

Alkaline.Processing.PropertyDescriptor.prototype.setDocComment = function(tree) {
	this.docComment = tree;
	tree.docCommentFor = this;
	var mods = Alkaline.Processing.PropertyDescriptor.ACCESS_MODIFIERS;
	var text = Alkaline.JSInfo.getCommentContent(tree);
	var m;
	for (var i = 0; i < mods.length; i++)
		if (m = text.match(mods.RegExps[i])) {
			this.access = mods[i];
			if (m.index)
				// m.index - 1 to remove the preceding newline character
				text = text.substr(0, m.index-1) + text.substr(m.index + m[0].length);
			else
				// m.index is 0
				text = text.substr(m[0].length);
		}
	this.docDescription = text.trim();
}

Alkaline.Processing.PropertyDescriptor.prototype.getFullDocComment = function() {
	var text = this.docDescription;
	if (this.access)
		text += '\n@' + this.access;
	
	return Alkaline.JSInfo.getCommentStringFromContent(text.trim());
}

Alkaline.Processing.PropertyDescriptor.prototype.setAccess = function(type) {
	this.access = type;
}
